/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import mockjs from 'mockjs';

const { mock } = mockjs;

/**
 *  格口统计，获取列表
 *  */
const codeStatistic = (req, res) => {
  const list = [];
  Array.from({ length: 20 }).forEach((_, index) => {
    list.push({
      sorting_line_code: index,
      brand: 'zt',
      grid_code: 'zt001',
      fp_num: '146',
      sj_num: '0',
      error_num: 146,
      zql: '0％',
    });
  });
  res.send({
    code: 0,
    msg: 'success',
    data: {
      list,
      page: 1,
      pageSize: 20,
      count: 20,
    },
  });
};

/**
 * 进港分拣，获取列表
 *  */
const listArrival = (req, res) => {
  const list = [];
  Array.from({ length: 20 }).forEach((_, index) => {
    list.push({
      id: index,
      shop_id: '7',
      sorting_line_id: '1',
      sorting_line_code: `${index}分拣线码`,
      waybill: '73223003900028',
      brand: '',
      img: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
      seq: 'seq2021-07-23 02:31:02',
      one_code: '1',
      two_code: '2',
      three_code: '3',
      weight: '20kg',
      grid_code: 'grid_code',
      actual_grid_code: 'actual_grid_code',
      is_accuracy: '0',
      gbt_no: 'gbt-001',
      gbt_scan_time: '2021-07-23 10:31:02',
      dj_time: '2021-07-23 10:31:02',
      dj_status: '0',
      send_time: '2021-07-23 10:31:02',
      send_status: '0',
      pj_time: '2021-07-23 10:31:02',
      pj_status: '0',
      next_dj_time: '2021-07-23 10:31:02',
      next_dj_status: '0',
      next_pj_time: '2021-07-23 10:31:02',
      next_pj_status: '0',
      luoge_time: '2021-07-23 10:31:02',
      addr_keys:
        '北京、上海、深圳、北京、上海、深圳、北京、上海、深圳、北京、上海、深圳、北京、上海、深圳、北京、上海、深圳',
      gbt_status: '识别状态',
    });
  });
  res.send({
    code: 0,
    msg: 'success',
    data: {
      list,
      page: 1,
      pageSize: 20,
      totalCount: 20,
    },
  });
};

/**
 * 格口配置，获取分拣线下拉数据
 *  */
const getLineList = (req, res) => {
  const list = [];
  Array.from({ length: 40 }).forEach((_, index) => {
    list.push({
      id: index,
      shop_id: index,
      sorting_line_code: index,
      sorting_line_name: `分拣线名称${index}`,
      sn_code: 'sn码',
      sorting_line_type: '1',
      sorting_line_token: '123131312',
      brand: 'sf',
      status: '1',
      up_scanner: '17521161691',
      down_scanner: '13262627065',
      create_time: '2021-07-02 15:26:01',
      update_time: '2021-07-02 15:26:01',
    });
  });
  res.send({
    code: 0,
    msg: 'success',
    data: list,
  });
};

export default {
  // 分拣线配置，获取支持的品牌
  'POST /Api/Automation/SortLine/listBrand': (req, res) => {
    res.send({
      code: 0,
      msg: 'success',
      data: [
        {
          brand: 'all',
          name: '全部品牌',
        },
        {
          brand: 'sto',
          name: '申通',
        },
        {
          brand: 'zt',
          name: '中通',
        },
        {
          brand: 'ht',
          name: '百世',
        },
        {
          brand: 'yd',
          name: '韵达',
        },
        {
          brand: 'yt',
          name: '圆通',
        },
        {
          brand: 'jt',
          name: '极兔',
        },
        {
          brand: 'ems',
          name: '邮政',
        },
        {
          brand: 'zykd',
          name: '众邮',
        },
        {
          brand: 'fw',
          name: '丰网',
        },
      ],
    });
  },
  // 分拣线配置，获取列表
  'POST /Api/Automation/SortLine/list': (req, res) => {
    const list = [];
    Array.from({ length: 20 }).forEach((_, index) => {
      list.push({
        id: index,
        shop_id: '7',
        sorting_line_code: `13899992222_${index}2`,
        sorting_line_name: `${index}_分拣线名称`,
        sn_code: 'sn码',
        sorting_line_type: index % 2 ? '1' : '2',
        zt_token: 'zt',
        ht_token: 'ht',
        // sorting_line_token: "",
        sorting_line_token:
          '{"zt":{"key":"51405-001"},"ht":{"key":"test001"},"sto":{"isDao":"0"},"jt":{"type":"0"}}',
        brand: index % 2 ? 'sto,yt,jt,post,ht,yd' : 'zt,yt',
        up_scanner: `${index}默认上线扫描员`,
        down_scanner: `${index}默认下线扫描员`,
        create_time: '2021-07-02 15:23:15',
        update_time: '2021-07-02 15:23:15',
        start_plan: '["15:00", "", "16:02"]',
      });
    });
    res.send({
      code: 0,
      msg: 'success',
      data: list,
    });
  },
  // 分拣线配置，删除列表
  'POST /Api/Automation/SortLine/delete': (req, res) => {
    res.send({
      code: 0,
      msg: 'success',
      data: {},
    });
  },
  // 分拣线配置，新增分拣线
  'POST /Api/Automation/SortLine/save': (req, res) => {
    res.send({
      code: 0,
      msg: 'success',
      data: {},
    });
  },
  // 分拣线配置，授权码列表
  'POST /Api/Automation/SortLineToken/list': (req, res) => {
    res.send({
      code: 0,
      msg: 'success',
      data: [
        {
          id: '1',
          sorting_line_id: '1',
          type: '授权对象',
          gbt_no: '123',
          token: '045940b3842f2563d78ca0cab982c9ac174a904e',
          status: '1',
          is_deleted: '0',
          create_time: '2021-07-22 10:01:24',
          update_time: '2021-07-22 10:01:24',
          auth_time: '2021-07-22 10:01:24',
        },
      ],
    });
  },
  // 分拣线配置，取消授权
  'POST /Api/Automation/SortLineToken/del': (req, res) => {
    res.send({
      code: 0,
      msg: 'success',
      data: {},
    });
  },
  // 分拣线配置，获取授权码
  'POST /Api/Automation/SortLineToken/addToken': (req, res) => {
    res.send({
      code: 0,
      msg: 'success',
      data: [
        {
          code: '1234567890',
        },
      ],
    });
  },
  // 分拣线配置，分拣线编号检测
  'POST /Api/Automation/SortLine/checkCode': (req, res) => {
    res.send({
      code: 0,
      msg: 'success',
      data: 0,
    });
  },
  // 分拣线配置，获取上下线扫描员
  'POST /Api/Automation/SortLine/salesmanList': (req, res) => {
    res.send({
      code: 0,
      msg: 'success',
      data: [
        {
          id: '134',
          company_info_id: '13',
          company_site_id: '0',
          courier_kb_id: '0',
          kdy_id: '0',
          courier_no: '000200002',
          courier_code: '002',
          courier_name: '苹果2',
          courier_phone: '18550031231',
          type: '0',
          switch: '1',
          is_waybill_open: '1',
          allowance_count: '7',
          created_at: '2020-08-17 09:47:06',
          updated_at: '2020-08-17 09:47:06',
          deleted_at: null,
          status: '1',
          user_type: '1',
        },
        {
          id: '1343',
          company_info_id: '13',
          company_site_id: '0',
          courier_kb_id: '0',
          kdy_id: '0',
          courier_no: '000200003',
          courier_code: '003',
          courier_name: '苹果1',
          courier_phone: '18550031232',
          type: '0',
          switch: '1',
          is_waybill_open: '1',
          allowance_count: '7',
          created_at: '2020-08-17 09:47:06',
          updated_at: '2020-08-17 09:47:06',
          deleted_at: null,
          status: '1',
          user_type: '1',
        },
      ],
    });
  },
  // 分拣线配置，设置分拣模式
  'POST /Api/Automation/SortLine/saveModel': (req, res) => {
    res.send({
      code: 0,
      msg: 'success',
      data: {},
    });
  },

  // 格口配置，获取列表
  'POST /Api/Automation/GeKou/list': (req, res) => {
    const list = [];
    Array.from({ length: 40 }).forEach((_, index) => {
      list.push({
        id: index,
        shop_id: index,
        sorting_line_id: `${index}1`,
        sorting_line_code: `${index}9`,
        grid_type: index % 2 ? 1 : 2,
        addr_keys:
          index % 2
            ? '北京、上海、深圳、北京、上海、深圳、北京、上海、深圳、北京、上海、深圳、北京、上海、深圳、北京、上海、深圳'
            : '',
        gbt_status: index % 2 ? '识别状态' : '',
        brand: 'yd',
        branch_code: 'branch_code11',
        grid_code: index,
        grid_name: `${index}__dasdasd`,
        error_grid_type: index % 2 ? '' : '1',
        down_scanner_type: '2',
        down_scanner_object: '15179185977',
        down_scanner_object_name: null,
        lower_node_dispatch: '15179185977',
        lower_node_dispatch_name: '哈哈哈哈',
        one_code: '3123',
        two_code: 'dasd',
        three_code: 'dasd',
        create_time: '2021-07-02 18:23:19',
        update_time: '2021-07-02 18:23:19',
      });
    });
    res.send({
      code: 0,
      msg: 'success',
      data: {
        list,
        page: 1,
        pageSize: 20,
        count: 40,
      },
    });
  },
  // 格口配置，导入配置
  'POST /Api/Automation/GeKou/upload': (req, res) => {
    res.send({
      code: 0,
      msg: 'success',
      data: {},
    });
  },
  // 格口配置，获取分拣线下拉数据
  'POST /Api/Automation/GeKou/getLineList': getLineList,
  // 格口配置，获取分拣线下拉数据（本地服务器）
  'POST /admin/SortLine/getLineList  ': getLineList,
  // 格口配置，删除配置
  'POST /Api/Automation/GeKou/del': (req, res) => {
    res.send({
      code: 0,
      msg: 'success',
      data: {},
    });
  },
  // 格口配置，新增异常口
  'POST /Api/Automation/GeKou/addType2': (req, res) => {
    res.send({
      code: 0,
      msg: 'XX品牌异常口已存在，请勿重复添加',
      data: {},
    });
  },
  // 格口配置，新增正常格口
  'POST /Api/Automation/GeKou/save': (req, res) => {
    res.send({
      code: 1,
      msg: 'XX品牌异常口已存在，请勿重复添加',
      data: {},
    });
  },
  // 格口配置，编辑异常、正常格口
  'POST /Api/YZ/CourierStation/editGrid': (req, res) => {
    res.send({
      code: 1,
      msg: 'XX品牌异常口已存在，请勿重复添加',
      data: {},
    });
  },
  // 格口配置，新增异常、正常格口，网点编号查询
  'POST /Api/Automation/GeKou/getBranchCode': (req, res) => {
    const { brand } = req.body;
    let data = `${brand}0123456789`;
    if (brand === 'sto' || !brand) {
      data = '';
    }

    res.send({
      code: 0,
      msg: 'success',
      data,
    });
  },
  // 格口配置，新增正常格口，获取下节点操作对象
  'POST /Api/Automation/GeKou/getDownScannerObject': (req, res) => {
    const { down_scanner_type: downScannerType } = req.body;
    const list =
      downScannerType === '3'
        ? [
            {
              branch_code: '410093',
              brand: 'ht',
              create_time: '2021-03-01 16:19:17',
              id: '134',
              kb_id: '7',
              station_code: '999957',
              station_name: '长沙分拨中心',
              station_type: '1',
              update_time: '2021-03-01 16:19:17',
            },
          ]
        : [
            {
              id: '11',
              company_info_id: '13',
              company_site_id: '10',
              courier_kb_id: '51669264',
              kdy_id: '1957428',
              courier_no: '000200035',
              courier_code: '035',
              courier_name: '骗你的哈',
              courier_phone: '15179185977',
              type: '0',
              switch: '1',
              is_waybill_open: '1',
              allowance_count: '10',
              created_at: '2020-07-30 10:08:49',
              updated_at: '2020-07-30 10:08:49',
              deleted_at: null,
              status: '1',
              user_type: '1',
            },
            {
              id: '2358',
              company_info_id: '13',
              company_site_id: '0',
              courier_kb_id: '67902670',
              kdy_id: '2225404',
              courier_no: '0002004',
              courier_code: '004',
              courier_name: '花花',
              courier_phone: '18600000001',
              type: '0',
              switch: '1',
              is_waybill_open: '2',
              allowance_count: '-1',
              created_at: '2021-04-14 15:00:33',
              updated_at: '2021-04-14 15:00:33',
              deleted_at: null,
              status: '1',
              user_type: '1',
            },
          ];

    res.send({
      code: 0,
      msg: 'success',
      data: list,
    });
  },
  // 进港分拣，获取列表
  'POST /Api/Automation/SortLine/listArrival': listArrival,
  // 进港分拣，获取列表(本地服务器)
  'POST /admin/SortLine/listArrival ': listArrival,
  // 格口统计，获取列表
  'POST /Api/Automation/GeKou/codeStatistic': codeStatistic,
  // 格口统计，获取列表(本地服务器)
  'POST /admin/SortLine/codeStatistic': codeStatistic,
  // 格口配置，下发配置
  'POST /Api/Automation/GeKou/sysData': (req, res) => {
    res.send({
      code: 0,
      msg: 'success',
      data: {},
    });
  },
  // 地址分拣，地址分拣列表
  'POST /Api/Automation/addrScheme/list': (req, res) => {
    const { page, size } = req.body;
    res.send(
      mock({
        msg: '成功',
        code: 0,
        data: {
          [`list|${size}`]: [
            {
              addr_scheme: '上海市+北翟路+(100-200奇数)、北京市+长安路+(100-200偶数)',
              'codes|1': ['1,2,4', '7,8,9'],
              create_time: '@date',
              'id|+1': 1,
              is_deleted: '0',
              shop_id: '7',
              sort: '001',
              sorting_line_code: '18721008363_09',
              'sorting_line_id|+1': 1,
              update_time: '@date',
            },
          ],
          total: 200,
          page,
        },
      }),
    );
  },
  // 地址分拣，删除配置
  'POST /Api/Automation/addrScheme/del': (req, res) => {
    res.send({
      code: 0,
      msg: 'success',
      data: {},
    });
  },
  // 地址分拣，新增配置
  'POST /Api/Automation/addrScheme/save': (req, res) => {
    res.send({
      code: 0,
      msg: 'success',
      data: {},
    });
  },
  // 地址分拣，获取已使用的优先级
  'POST /Api/Automation/addrScheme/sortList': (req, res) => {
    res.send({
      code: 0,
      msg: 'success',
      data: [1, 2, 4],
    });
  },
  // 判断是否是老用户
  'POST /Api/Automation/SortLine/config': (req, res) => {
    res.send({
      code: 0,
      msg: 'success',
      data: {
        isOldUser: 1,
      },
    });
  },
};
